﻿/*** This script will only run if the version number in the databse is less than 01.20.00 ***/
if((SELECT REPLACE(VersionNumber,'.','') FROM Version) < '012000')
BEGIN

	/****** Object: Update Table [dbo].[SilverlightDesktopModules] ******/
	/** Add two additinal colums **/
	BEGIN TRANSACTION
	
	CREATE TABLE dbo.Tmp_SilverlightDesktopModules
		(
		ModuleID int NOT NULL IDENTITY (1, 1),
		ModuleName nvarchar(50) NOT NULL,
		ModuleDescription nvarchar(100) NOT NULL,
		AssemblyName nvarchar(50) NOT NULL,
		ClassName nvarchar(50) NOT NULL,
		IconName nvarchar(50) NOT NULL,
		Role nvarchar(50) NOT NULL,
		WindowSize int NOT NULL,
		AllowMultipleInstances bit NOT NULL,
		ModuleVersion int NOT NULL,
		uninstall ntext NOT NULL
		)  ON [PRIMARY]
		 TEXTIMAGE_ON [PRIMARY]
	
	SET IDENTITY_INSERT dbo.Tmp_SilverlightDesktopModules ON
	
	IF EXISTS(SELECT * FROM dbo.SilverlightDesktopModules)
		 EXEC('INSERT INTO dbo.Tmp_SilverlightDesktopModules (ModuleID, ModuleName, ModuleDescription, AssemblyName, ClassName, IconName, Role, WindowSize, AllowMultipleInstances, ModuleVersion, uninstall)
			SELECT ModuleID, ModuleName, ModuleDescription, AssemblyName, ClassName, IconName, Role, WindowSize, AllowMultipleInstances, 0 as ModuleVersion, '''' as uninstall FROM dbo.SilverlightDesktopModules WITH (HOLDLOCK TABLOCKX)')
	
	SET IDENTITY_INSERT dbo.Tmp_SilverlightDesktopModules OFF
	
	DROP TABLE dbo.SilverlightDesktopModules
	
	EXECUTE sp_rename N'dbo.Tmp_SilverlightDesktopModules', N'SilverlightDesktopModules', 'OBJECT' 
	
	ALTER TABLE dbo.SilverlightDesktopModules ADD CONSTRAINT
		PK_SilverlightDesktopModules PRIMARY KEY CLUSTERED 
		(
		ModuleID
		) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

	
	COMMIT


	/****** Object:  Table [dbo].[ModuleFiles] ******/
	IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[SilverlightDesktopModuleFiles]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
	BEGIN
	CREATE TABLE [dbo].[SilverlightDesktopModuleFiles](
		[ID] [int] IDENTITY(1,1) NOT NULL,
		[ModuleName] [nvarchar](50) NOT NULL,
		[FileNameAndPath] [nvarchar](500) NOT NULL,
	 CONSTRAINT [PK_ModuleFiles] PRIMARY KEY CLUSTERED 
	(
		[ID] ASC
	) ON [PRIMARY]
	) ON [PRIMARY]
	END
	
	/** Alter SilverlightDesktopUsers **/
	ALTER TABLE dbo.SilverlightDesktopUsers ADD
	IPAddress nvarchar(50) NULL
	
	/** Update Version **/
	DELETE FROM Version
	INSERT INTO Version(VersionNumber) VALUES (N'01.20.00')

END